<?php 
	namespace app\admin\controller;
	use \think\Controller;
	/**
	* 配置项
	*/
	class Config extends Base
	{	
		public $config;
		//$this->config=model("TkConfigs");
		//展示配置项列表
		public function _config(){
			$config=model("TkConfigs");
			$dataobj=$config->select();
			//dump($dataobj);
			foreach ($dataobj as $value) {
				$data[]=$value->toArray();
			}
			// print_r($data);
			$this->assign("data",$data);
			return $this->fetch();
		}
		//添加配置项
		public function add_config(){
			if(request()->isPost()){
				//dump(input("param."));
				$config=model("TkConfigs");
				$contitle=input("param.contitle");
				$count=count($config->where("contitle='$contitle'")->select());
				if($count==0){
					$num=$config->allowField(true)->save(input("param."));
					if($num==1){
						$this->success("添加成功",'_config','',1);
					}else{
						$this->error("添加失败,请重新添加",'','',1);
					}	
				}else{
					$this->error("请不要添加重复配置项",'','',1);
				}
							
				//exit;
			}else{
				$id=input("param.id");
				return $this->fetch();
			}
		}
		//修改配置项
		public function edit_config(){
			$config=model("TkConfigs");
			if(request()->isPost()){
				// dump(input("param."));
				$num=$config->allowField(true)->save(input("param."),['id'=>input("param.id")]);
				//echo $config->getLastSql();
				if($num==1){
					$this->success("修改成功",'_config','',1);
				}else{
					$this->error("请重新修改",'','',1);
				}
			}else{
				$id=input("param.id");
				$data=$config->where("id=$id")->find()->toArray();
				//print_r($data);
				$this->assign("data",$data);
				//echo $config->getLastSql();
				//exit;
				return $this->fetch();
			}
		}
		//删除配置项
		public function del_config(){
			$id=input("param.id");
			$config=model("TkConfigs");
			$num=$config->where("id=$id")->delete();
			// echo $config->getLastSql();
			if($num==1){
					$this->success("删除成功",'_config','',1);
				}else{
					$this->error("请重新删除",'_config','',1);
				}		
		}
	
	}
?>